#ifndef DDCPITEMFACTORY_HPP__
#define DDCPITEMFACTORY_HPP__

#include <map>

#include "DDCPBodyConfigure.hpp"
#include "DDCPItemTypes.hpp"
#include "DDCPItem.hpp"


#define DDCP_CLASSREGISTER(_enum, _manager) _manager##->Register(#_enum, new CDDCPItemFactory<CDDCP##_enum>)

class SIPBODYXML_PUBLIC CDDCPItemAbstractFactory{
public:
    CDDCPItemAbstractFactory(){}
    virtual ~CDDCPItemAbstractFactory(){}
    virtual void* creat() = 0;
};

template <class T>
class SIPBODYXML_PUBLIC CDDCPItemFactory: public CDDCPItemAbstractFactory{
public:
    CDDCPItemFactory(){}
    virtual ~CDDCPItemFactory(){}

    virtual void* creat(){
        T* ret = new T;
        return (void*)ret;
    }

};

class SIPBODYXML_PUBLIC CDDCPItemManager{
public:
    virtual ~CDDCPItemManager();
    static CDDCPItemManager* instance();
    
    bool Register(char* classEnum, CDDCPItemAbstractFactory* fact);

    bool unRegister(char* classEnum);

    CDDCPItem* creat(char* classEnum);

private:
    std::map<char*, CDDCPItemAbstractFactory*> m_regTable;
    static CDDCPItemManager* s_manager;

private:
    CDDCPItemManager();

};




#endif
